﻿using System.Collections.Generic;
using System.Collections.ObjectModel;

using Outcoder;
using Outcoder.ComponentModel;
using Outcoder.Services;
using Outcoder.UI.Xaml;

namespace CalciumTemplateApp
{
	/// <summary>
	/// This class contains child viewmodels, which are presented in a pivot.
	/// The ActivateViewModel method allows validation 
	/// to switch to a particular viewmodel in the pivot.
	/// </summary>
	public class DashboardViewModel : CustomViewModel, ICompositeViewModel
	{
		public DashboardViewModel() : base(AppResources.Page_Dashboard_Title)
		{
		}

		readonly IEnumerable<ViewModelBase> childViewModels 
			= new ObservableCollection<ViewModelBase>
		            {
		                new OptionsViewModel(),
						new HelpViewModel(),
						new AboutViewModel()
		            };

		/// <summary>
		/// Gets the child view models that are displayed in the pivot.
		/// </summary>
		public IEnumerable<ViewModelBase> ChildViewModels
		{
			get
			{
				return childViewModels;
			}
		}

		ViewModelBase selectedViewModel;

		/// <summary>
		/// Gets or sets the selected view model in the pivot.
		/// </summary>
		/// <value>
		/// The selected view model.
		/// </value>
		public ViewModelBase SelectedViewModel
		{
			get
			{
				return selectedViewModel;
			}
			set
			{
				Assign(ref selectedViewModel, value);
			}
		}

		public void ActivateViewModel(ViewModelBase viewModel)
		{
			/* Setting the SelectedViewModel property 
			 * sets the selected item in the pivot. 
			 * See the binding expression for the pivot's SelectedItem property 
			 * in the view XAML. */
			SelectedViewModel = viewModel;
		}
	}
}
